package com.groupa.project1.swing;


import com.groupa.project1.chat.ContentClass;
import com.groupa.project1.chat.InstantMessageClass;
import com.groupa.project1.database.PhotoClass;
import com.sun.media.jai.widget.DisplayJAI;
import java.awt.Dimension;
import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;
import javax.swing.BoxLayout;
import javax.swing.JScrollPane;


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


/*
 * inici.java
 *
 * Created on 14-feb-2012, 17:29:50
 */
/**
 *
 * @author JoWi
 */
public class login extends javax.swing.JFrame {
    
        private static editorsMenu M;
        private static String emailLogin;
        PlanarImage image;
        DisplayJAI dj;
        JScrollPane newImagePane;
        boolean editor=false;
        boolean photographer=false;

    /** Creates new form inici */
    public login() {
        initComponents();
        incorrectLabel.setVisible(false); //fiquem etiqueta de usuari o password incorrecte
        electionLabel.setVisible(false);
        
                
        //path =Prop.getProperty("StoreThumbnail/path") + name;
      //  String userDir= System.getProperty("user.dir");
       // image = JAI.create("fileload", "com.groupa.project1.swing.logo_fondogris.png");        //C:/Users/JoWi/Documents/NetBeansProjects/trunk/Project1/trunk/Project1/src/main/java/com/groupa/project1/swing/logo_fondogris.png");
       /// dj = new DisplayJAI(image);
        //newImagePane = new JScrollPane(dj);
        //jPanel1.setPreferredSize(new Dimension(79,80));
        //jPanel1.setLayout(new BoxLayout(jPanel1,BoxLayout.PAGE_AXIS));
        //jPanel1.add(newImagePane);
        setVisible(true);
    }
    
    
    public static String getLogin(){
        return emailLogin;
    }
     
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        passwordLogin = new javax.swing.JPasswordField();
        usernameLogin = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        LoginButton = new javax.swing.JButton();
        incorrectLabel = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        editorButton = new javax.swing.JRadioButton();
        photographerButton = new javax.swing.JRadioButton();
        electionLabel = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        passwordLogin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                passwordLoginActionPerformed(evt);
            }
        });

        usernameLogin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                usernameLoginActionPerformed(evt);
            }
        });

        jLabel1.setText("E-mail:");

        jLabel2.setText("Password:");

        LoginButton.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        LoginButton.setText("Login");
        LoginButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LoginButtonActionPerformed(evt);
            }
        });

        incorrectLabel.setForeground(new java.awt.Color(255, 0, 0));
        incorrectLabel.setText("Incorrect email or password");

        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel16.setText("SHAREPHOTO.COM");

        editorButton.setText("Editor");
        editorButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editorButtonActionPerformed(evt);
            }
        });

        photographerButton.setText("Photographer");
        photographerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                photographerButtonActionPerformed(evt);
            }
        });

        electionLabel.setForeground(new java.awt.Color(255, 0, 0));
        electionLabel.setText("Select photographer or editor");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 80, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 81, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(188, 188, 188)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(LoginButton)
                                .addComponent(jLabel16)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel1)
                                        .addGap(18, 18, 18)
                                        .addComponent(usernameLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel2)
                                        .addGap(18, 18, 18)
                                        .addComponent(passwordLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addComponent(photographerButton)
                                        .addGap(18, 18, 18)
                                        .addComponent(editorButton))))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(16, 16, 16)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(incorrectLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(electionLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(235, 235, 235)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(184, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel2});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {passwordLogin, usernameLogin});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(99, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(usernameLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(passwordLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(5, 5, 5)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(photographerButton)
                    .addComponent(editorButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(LoginButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(incorrectLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(electionLabel)
                .addGap(85, 85, 85))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jLabel1, jLabel2});

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void usernameLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_usernameLoginActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_usernameLoginActionPerformed

private void passwordLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_passwordLoginActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_passwordLoginActionPerformed

private void LoginButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LoginButtonActionPerformed
 // TODO add your handling code here:
    
   InstantMessageClass instance = null;
    instance= (InstantMessageClass) instance.GetInstance();
    emailLogin= usernameLogin.getText();
    if (photographerButton.isSelected()){
        if(instance.login(usernameLogin.getText(),passwordLogin.getText(),"Home") == true){
            incorrectLabel.setVisible(false);
            photographersMenu pm = photographersMenu.getPhotographersMenu();
            pm.setVisible(true);
            this.setVisible(false);
            
        }
        else{
            incorrectLabel.setVisible(true);
            electionLabel.setVisible(false);
            
        }
    }
    else if (editorButton.isSelected()){
        if(instance.login(usernameLogin.getText(),passwordLogin.getText(),"Home") == true){
            incorrectLabel.setVisible(false);
            M=editorsMenu.getEditorsMenu();
            M.setVisible(true);
            this.setVisible(false);
        }
        else{
            incorrectLabel.setVisible(true);
            electionLabel.setVisible(false);
        }
    }
   else{
        electionLabel.setVisible(true);
    }
}//GEN-LAST:event_LoginButtonActionPerformed

private void photographerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_photographerButtonActionPerformed
// TODO add your handling code here:
    editorButton.setSelected(false);
}//GEN-LAST:event_photographerButtonActionPerformed

    private void editorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editorButtonActionPerformed
         photographerButton.setSelected(false);
            
        
    }//GEN-LAST:event_editorButtonActionPerformed



    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new login().setVisible(true);
                
            }
        });
    }
        
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton LoginButton;
    private javax.swing.JRadioButton editorButton;
    private javax.swing.JLabel electionLabel;
    private javax.swing.JLabel incorrectLabel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPasswordField passwordLogin;
    private javax.swing.JRadioButton photographerButton;
    private javax.swing.JTextField usernameLogin;
    // End of variables declaration//GEN-END:variables
}
